package com.example.jpademo.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 有关模板引擎thymeleaf的例子
 */

@Controller
@RequestMapping("")
public class ThymeleafController {

    @GetMapping({"/index", "/index.html"})
    public ModelAndView index() {
        List<String> list = new ArrayList<>();
        list.add("北京");
        list.add("上海");
        list.add("深圳");
        list.add("香港");
        list.add("广州");
        Map<String, Object> map = new HashMap<>();
        map.put("name", "张三");
        map.put("age", "18");
        map.put("address", "上海");
        ModelAndView modelAndView = new ModelAndView("index");
        modelAndView.addObject("list", list);
        modelAndView.addObject("map", map);
        modelAndView.addObject("name", "admin");
        return modelAndView;
    }
}
